---@class UITimeBoxEffectBox : UIBase
UITimeBoxEffectBox = UIBase.New(PanelResNames.UITimeBoxEffectBox)
local t = UITimeBoxEffectBox

local parobj = nil
local parDraw = nil
local colors = {}
function t.Init(boxModelId,rewards)
    t.boxModelId = boxModelId
    t.rewards = rewards
    UIBase.Init(t)
end

function t:OnCreate()
    ---@type FairyGUI.GLoader3D
    colors["shine"]={"473EE7","5F3EE7","E78F3E","E06F71"}
    colors["glow_02"]={"3E4293","5A3E93","93633E","933E3E"}
    colors["glow_04"]={"9A6FEE","9A6FEE","9A7C34","EE6F6F"}
    self.graphStart = self :GetChild("Graph_mf")
    self.Effect_mf = self:GetChild("Effect_mf")
    self.effAnim = self.Effect_mf.wrapTarget
end

function t:OnEnable()
    self:Refresh()
end
function t:OnDisable()
    self:DisPose()
end
function t:OnDestroy()
    self:DisPose()
end

function t:DisPose()
    if parDraw then
        parDraw:Dispose()
        parDraw = nil
    end
    if not HelperFunc.IsNull(parobj) then
        destroyImmediate(parobj)
        parobj = nil
    end
end

function t:LoadPar(index)
    resMgr:LoadModelPrefab("UIEff/UI_mojing_boom", function(go)
        self:DisPose()
        parDraw = GoWrapper.New()
        parobj = newObject(go);
        parobj:SetActive(true);
        parobj:AddComponent(TCanvas);
        parobj:AddComponent(TChangeSortingOrder);
        parDraw:SetWrapTarget(parobj,false)
        self.graphStart:SetNativeObject(parDraw)
        if not HelperFunc.IsNull(parobj) then
            Util.Lua_SetLocalPositionXYZ(parobj.transform, 0, 0, 0)
            for i=0,parobj.transform.childCount -1 do
                local trans = parobj.transform:GetChild(i):GetComponent("ParticleSystem")
                if colors[trans.name] then
                    local mat = parobj.transform:GetChild(i):GetComponent("Renderer").material
                    local r,g,b,a = HelperFunc.GetColorOfRGB(colors[trans.name][index])
                    mat:SetColor("_TintColor",Color.New(r/255,g/255,b/255,a/255))
                end
            end
        end
    end)
end

function t:Refresh()
    local id = t.boxModelId
    local index = table.containsIndex(TimeBoxHandler.CONST_BOX_ID_LIST,id)
    self:LoadPar(index)
    self.Effect_mf.skinName = tostring(index)
    local time = Util.PlayAction(self.effAnim,"idle2",false)
    utimer.delayCall(function()
        logicMgr.UIShowManager.ShowRewardByTempItemInfo(t.rewards)
        closeUI(PanelNames.UITimeBoxEffectBox)
    end,time*1000)
end
return t